<?php

namespace App\Http\Controllers\admin\product;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

use App\Models\User;
use App\Models\User_info;
use App\Models\Doctor;
use App\Models\District;
use App\Models\Address;
use App\Models\Cart;
use App\Models\Order;
use App\Models\Order_info;
use App\Models\Order_time;
use App\Models\Sender;

class OrderController extends Controller
{
    public function index()
    {
        $status = [1 => '待付款', 2 => '待发货', 3 => '待收货', 4 => '待评价', 5 => '已完成', 6 => '已取消'];
        $order = new Order();
        $list = $order->storeOrder();
        $sender = new Sender();
        $row = $sender->selSender();
        return view('admin.product.orderlist',['list'=>$list, 'status' => $status, 'sender' => $row]);
    }

    public function allocation(Request $request)
    {
        //修改平台状态
        $id = $request->input('order_id');
        $order =  Order::find($id);
        $order->state = 4;
        $order->sender_id = $request->input('id');
        $order->save();
        //修改配货时间
        $order_time = new Order_time();
        $row = $order_time->store_at($id);
        if($row){
            return json_encode(true);
        }else{
            return json_encode(false);
        }
    }
}
